package com.ems.controller;

import com.ems.service.IBatteryTempService;
import com.ems.vo.BaseResult;
import com.ems.vo.BatteryTempVo;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 电池电感温度 前端控制器
 * </p>
 *
 * @author WuZH
 * @since 2024-04-23
 */
@RestController
@RequestMapping ( "/batteryTemp" )
@CrossOrigin ( value = "*", maxAge = 3600 )
public class BatteryTempController {

    @Resource
    private IBatteryTempService iBatteryTempService;

    @RequestMapping ( "queryList" )
    public BaseResult queryList ( @RequestBody BatteryTempVo batteryTempVo ) {
        List<BatteryTempVo> batteryTempVos = iBatteryTempService.queryList ( batteryTempVo );
        batteryTempVo = batteryTempVos.get ( 0 );
        String[] split1 = batteryTempVo.getTemp1 ().split ( ";" );
        String[] split2 = batteryTempVo.getTemp2 ().split ( ";" );
        String[] split3 = batteryTempVo.getTemp3 ().split ( ";" );
        String[] split4 = batteryTempVo.getTemp4 ().split ( ";" );
        String[] split5 = batteryTempVo.getTemp5 ().split ( ";" );
        String[] split6 = batteryTempVo.getTemp6 ().split ( ";" );
        int count = split1.length + split2.length + split3.length + split4.length + split5.length + split6.length;
        return BaseResult.success ( batteryTempVos, count );
    }

    @RequestMapping ( "saveSingle" )
    public BaseResult saveSingle ( @RequestBody BatteryTempVo batteryTempVo ) {
        batteryTempVo = iBatteryTempService.saveSingle ( batteryTempVo );
        return BaseResult.success ( batteryTempVo );
    }

}
